package com.wdh.kjs.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.Adapter.FM_financerecord_Adapter;
import com.wdh.kjs.Adapter.FM_raising_Adapter;
import com.wdh.kjs.Adapter.ListViewForScrollView;
import com.wdh.kjs.Adapter.MF_invest_Adapter;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel_my;
import com.wdh.kjs.util.DateUtilChange;
import com.wdh.kjs.util.DateUtils;
import com.wdh.kjs.util.ToastUtils;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Created by chenqinhuang on 2016/4/3.
 */
public class Finance_manage_Fragment extends Fragment {

    private PullToRefreshListView listView;
    private FM_financerecord_Adapter FM_financerecord;
    private FM_raising_Adapter FM_raise_three;
    //    private ScrollView scrollView;
    public int QUERY_TYPE = 0;
    private JsonModel_my jsonModel_my;
    private String partyId;
    private Context context;
    private Activity activity;
    public static int page = 1;
    public static int rows = 3;
    public static int totalrecords = 0;
    public boolean mLoading = true;
    private List<HashMap<String, String>> datas = new ArrayList<HashMap<String, String>>();
    private TextView warnMessage;//“暂无内容”Textviwe
    private String time;
    private String m;
    private String gdBenefitReturnStep;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_financemanage_2, container, false);
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("logininfo", Context.MODE_PRIVATE);
        partyId = sharedPreferences.getString("loginToken", "");
        initView(view);
        loadData();
        return view;
    }

    private void initView(View view) {
        listView = (PullToRefreshListView) view.findViewById(R.id.fragment_financemanage_listview);
        warnMessage = (TextView) view.findViewById(R.id.tv_fragment_financemanage_2);
    }

    private void loadData() {
        mLoading = true;
        page = 1;
        rows = 3;
        switch (QUERY_TYPE) {
            case 0:
                RequestParams params = new RequestParams();
                params.addBodyParameter("partyId", partyId);
                params.addBodyParameter("page", page + "");
                params.addBodyParameter("rows", rows + "");

                HttpUtils http = new HttpUtils();
                http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISERECORD, params, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        Gson gson = new Gson();
                        jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                        if (jsonModel_my.success) {
                            totalrecords = jsonModel_my.getTotalrecords();
                            if(totalrecords<=0){
                                warnMessage.setVisibility(View.VISIBLE);
                            }
                            FM_financerecord = new FM_financerecord_Adapter(getContext(), initListViewData());
                            listView.setAdapter(FM_financerecord);
                            setPulllistViewListener();
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        warnMessage.setText("网络异常");
                        warnMessage.setVisibility(View.VISIBLE);
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            case 1:
                RequestParams params_1 = new RequestParams();
                params_1.addBodyParameter("partyId", partyId);
                params_1.addBodyParameter("page", "1");
                params_1.addBodyParameter("rows", "3");
                params_1.addBodyParameter("itemStatus", "7");

                HttpUtils http_1 = new HttpUtils();
                http_1.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_1, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        Gson gson = new Gson();
                        jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                        if (jsonModel_my.success) {
                            totalrecords = jsonModel_my.getTotalrecords();
                            if(totalrecords<=0){
                                warnMessage.setVisibility(View.VISIBLE);
                            }
                            FM_raise_three = new FM_raising_Adapter(getContext(), initListViewData());
                            setPulllistViewListener();
                            listView.setAdapter(FM_raise_three);
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        warnMessage.setText("网络异常");
                        warnMessage.setVisibility(View.VISIBLE);
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            case 2:
                RequestParams params_2 = new RequestParams();
                params_2.addBodyParameter("partyId", partyId);
                params_2.addBodyParameter("page", page+"");
                params_2.addBodyParameter("rows", rows+"");
                params_2.addBodyParameter("itemStatus", "9");

                HttpUtils http_2 = new HttpUtils();
                http_2.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_2, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        Gson gson = new Gson();
                        jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                        if (jsonModel_my.success) {
                            totalrecords = jsonModel_my.getTotalrecords();
                            if(totalrecords<=0){
                                warnMessage.setVisibility(View.VISIBLE);
                            }
                            else {
                                FM_raise_three = new FM_raising_Adapter(getContext(), initListViewData());
                                listView.setAdapter(FM_raise_three);
                                setPulllistViewListener();
                            }
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        warnMessage.setText("网络异常");
                        warnMessage.setVisibility(View.VISIBLE);
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            case 3:
                RequestParams params_3 = new RequestParams();
                params_3.addBodyParameter("partyId", partyId);
                params_3.addBodyParameter("page", "1");
                params_3.addBodyParameter("rows", "3");
                params_3.addBodyParameter("itemStatus", "10");

                HttpUtils http_3 = new HttpUtils();
                http_3.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_3, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        Gson gson = new Gson();
                        jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                        if (jsonModel_my.success) {
                            totalrecords = jsonModel_my.getTotalrecords();
                            if(totalrecords<=0){
                                warnMessage.setVisibility(View.VISIBLE);
                            }
                            FM_raise_three = new FM_raising_Adapter(getContext(), initListViewData());
                            listView.setAdapter(FM_raise_three);
                            setPulllistViewListener();
                        } else {
                            warnMessage.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        warnMessage.setText("网络异常");
                        warnMessage.setVisibility(View.VISIBLE);
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
        }

    }

    private List<HashMap<String, String>> initListViewData() {
        datas = new ArrayList<>();
        switch (QUERY_TYPE) {
            case 0:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    if (jsonModel_my.getInvestitems().get(i).getInterestStartDate()!=0){
//                        time = DateUtilChange.timestamp2String(jsonModel_my.getRaiserecords().get(i).getItemStatusChangeTime(),DateUtilChange.DEFAULT_DAY_FORMAT);}
//                    else {
//                        time = "——";
//                    }
                    String time = DateUtilChange.timestamp2String(jsonModel_my.getRaiserecords().get(i).getItemStatusChangeTime(), DateUtilChange.DEFAULT_SECOND_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getRaiserecords().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getRaiserecords().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);
                    HashMap<String, String> hashMap = new HashMap<>();
                    if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == -1) {
                        hashMap.put("financeRecord_state", "请修改");}
                        else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 0) {
                        hashMap.put("financeRecord_state", "未提交");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 1) {
                        hashMap.put("financeRecord_state", "审核中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 2) {
                        hashMap.put("financeRecord_state", "上架信息待完善");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 3) {
                        hashMap.put("financeRecord_state", "待美工");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 4) {
                        hashMap.put("financeRecord_state", "待发送");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 5) {
                        hashMap.put("financeRecord_state", "待确认上线");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 6) {
                        hashMap.put("financeRecord_state", "上线失败");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 7) {
                        hashMap.put("financeRecord_state", "募集中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 8) {
                        hashMap.put("financeRecord_state", "预热中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 9) {
                        hashMap.put("financeRecord_state", "募集成功");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 10) {
                        hashMap.put("financeRecord_state", "募集终止");
                    }else if(jsonModel_my.getRaiserecords().get(i).getItemStatus() == 300){
                        hashMap.put("financeRecord_state", "期中终止");
                    }

                    if (jsonModel_my.getRaiserecords().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("financeRecord_repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getRaiserecords().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("financeRecord_repayType", "按月付息到期还本");
                    }
                    hashMap.put("financeRecord_name", jsonModel_my.getRaiserecords().get(i).getItemName().toString());
                    hashMap.put("financeRecord_annualRate", newrate1 + "%");
                    hashMap.put("financeRecord_projectTime", jsonModel_my.getRaiserecords().get(i).getInterestDays() + "天");
                    hashMap.put("financeRecord_investMoney", "￥" + new BigDecimal(jsonModel_my.getRaiserecords().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("financeRecord_date", time);
                    datas.add(hashMap);
                }
                break;
            case 1:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(),DateUtilChange.DEFAULT_DAY_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("state", "募集中");
                    hashMap.put("starttime", "-1");
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    datas.add(hashMap);
                }
                break;
            case 2:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    if (jsonModel_my.getInvestitems().get(i).getInterestStartDate()!=0){
//                        time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(),DateUtilChange.DEFAULT_DAY_FORMAT);}
//                    else {
//                        time = "——";
//                    }
                    long m = jsonModel_my.getMyraises().get(i).getInterestStartDate();
                    if (m!=0) {
                         time = DateUtilChange.timestamp2String(m, DateUtilChange.DEFAULT_DAY_FORMAT);
                    }else {
                        time = "——";
                    }
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String newrate1 = df.format(annualRate);
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("state", jsonModel_my.getMyraises().get(i).getGdBenefitReturnStep());
                    hashMap.put("starttime", time);
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    datas.add(hashMap);
                }
                break;
            case 3:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(),DateUtilChange.DEFAULT_DAY_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();

                  switch (jsonModel_my.getMyraises().get(i).getItemStatus()){
                      case "100":
                          m="已退还";
                          break;
                      case "200":
                          m="待退还";
                          break;
                  }

                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("state", m);
                    hashMap.put("starttime", "-1");
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    ;
                    datas.add(hashMap);
                }
                break;
        }
        return datas;
    }

    private void setPulllistViewListener() {
        listView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
        listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {

            // 下拉Pulling Down
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                // 下拉的时候数据重置
            }

            // 上拉Pulling Up
            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                // 上拉的时候添加选项

                String label = DateUtils.formatDateTime(getActivity().getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
                new GetDataTask().execute();
            }

        });
    }

    private class GetDataTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (mLoading) {
                page += 1;
                try {
                    getMoreList();
                } catch (Exception e) {
                    page -= 1;
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            if (mLoading == false)
                ToastUtils.showShort(getActivity(), "已无更多数据！");
            listView.onRefreshComplete();
            super.onPostExecute(aVoid);
        }
    }

    private void getMoreList() {
        switch (QUERY_TYPE) {
            case 0: {
                RequestParams params = new RequestParams();
                params.addBodyParameter("partyId", partyId);
                params.addBodyParameter("page", page + "");
                params.addBodyParameter("rows", rows + "");

                HttpUtils http = new HttpUtils();
                http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISERECORD, params, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        try {
                            Gson gson = new Gson();
                            jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                            if (jsonModel_my.success) {
                                getMoreListViewDate();
                            }
                        } catch (Exception e) {
                            mLoading = false;
                            page -= 1;
                            ToastUtils.showShort(getActivity(), "没有更多数据！");
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            }
            case 1: {
                RequestParams params_1 = new RequestParams();
                params_1.addBodyParameter("partyId", partyId);
                params_1.addBodyParameter("page", page + "");
                params_1.addBodyParameter("rows", rows + "");
                params_1.addBodyParameter("itemStatus", "7");

                HttpUtils http_1 = new HttpUtils();
                http_1.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_1, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        try {
                            Gson gson = new Gson();
                            jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                            if (jsonModel_my.success) {
                                getMoreListViewDate();
                            }
                        } catch (Exception e) {
                            mLoading = false;
                            page -= 1;
                            ToastUtils.showShort(getActivity(), "没有更多数据！");
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            }
            case 2: {
                RequestParams params_2 = new RequestParams();
                params_2.addBodyParameter("partyId", partyId);
                params_2.addBodyParameter("page", page + "");
                params_2.addBodyParameter("rows", rows + "");
                params_2.addBodyParameter("itemStatus", "9");

                HttpUtils http_2 = new HttpUtils();
                http_2.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_2, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        try {
                            Gson gson = new Gson();
                            jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                            if (jsonModel_my.success) {
                                getMoreListViewDate();
                            }
                        } catch (Exception e) {
                            mLoading = false;
                            page -= 1;
                            ToastUtils.showShort(getActivity(), "没有更多数据！");
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            }
            case 3: {
                RequestParams params_3 = new RequestParams();
                params_3.addBodyParameter("partyId", partyId);
                params_3.addBodyParameter("page", page + "");
                params_3.addBodyParameter("rows", rows + "");
                params_3.addBodyParameter("itemStatus", "10");

                HttpUtils http_3 = new HttpUtils();
                http_3.send(HttpRequest.HttpMethod.POST, Httpurl.URL_FM_RAISE, params_3, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        try {
                            Gson gson = new Gson();
                            jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                            if (jsonModel_my.success) {
                                getMoreListViewDate();
                            }
                        } catch (Exception e) {
                            mLoading = false;
                            page -= 1;
                            ToastUtils.showShort(getActivity(), "没有更多数据！");
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        ToastUtils.showShort(getActivity(), "网络异常！");
                    }
                });
                break;
            }
        }
    }

    private void getMoreListViewDate() {
        switch (QUERY_TYPE) {
            case 0:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
                    String time = DateUtilChange.timestamp2String(jsonModel_my.getRaiserecords().get(i).getItemStatusChangeTime(), DateUtilChange.DEFAULT_SECOND_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getRaiserecords().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getRaiserecords().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);

                    HashMap<String, String> hashMap = new HashMap<>();
                    if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == -1) {
                        hashMap.put("financeRecord_state", "请修改");
                    }else  if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 0) {
                        hashMap.put("financeRecord_state", "未提交");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 1) {
                        hashMap.put("financeRecord_state", "审核中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 2) {
                        hashMap.put("financeRecord_state", "上架信息待完善");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 3) {
                        hashMap.put("financeRecord_state", "待美工");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 4) {
                        hashMap.put("financeRecord_state", "待发送");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 5) {
                        hashMap.put("financeRecord_state", "待确认上线");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 6) {
                        hashMap.put("financeRecord_state", "上线失败");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 7) {
                        hashMap.put("financeRecord_state", "募集中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 8) {
                        hashMap.put("financeRecord_state", "预热中");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 9) {
                        hashMap.put("financeRecord_state", "募集成功");
                    } else if (jsonModel_my.getRaiserecords().get(i).getItemStatus() == 10) {
                        hashMap.put("financeRecord_state", "募集终止");
                    }else if(jsonModel_my.getRaiserecords().get(i).getItemStatus() == 300){
                        hashMap.put("financeRecord_state", "期中终止");
                    }

                    if (jsonModel_my.getRaiserecords().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("financeRecord_repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getRaiserecords().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("financeRecord_repayType", "按月付息到期还本");
                    }
                    hashMap.put("financeRecord_name", jsonModel_my.getRaiserecords().get(i).getItemName().toString());
                    hashMap.put("financeRecord_annualRate", newrate1 + "%");
                    hashMap.put("financeRecord_projectTime", jsonModel_my.getRaiserecords().get(i).getInterestDays() + "天");
                    hashMap.put("financeRecord_investMoney", "￥" + new BigDecimal(jsonModel_my.getRaiserecords().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("financeRecord_date", time);
                    datas.add(hashMap);
                }
                if (datas.size() == totalrecords) {
                    mLoading = false;
                } else {
                    totalrecords = datas.size();
                }
                if (mLoading == true) {
                    FM_financerecord.notifyDataSetChanged();
                }
                break;
            case 1:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(),DateUtilChange.DEFAULT_DAY_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);

                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("state", "募集中");
                    hashMap.put("starttime", "-1");
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    datas.add(hashMap);
                }
                if (datas.size() == totalrecords) {
                    mLoading = false;
                } else {
                    totalrecords = datas.size();
                }
                if (mLoading == true) {
                    FM_raise_three.notifyDataSetChanged();
                }
                break;
            case 2:
//                jsonModel_my.getMyraises().size()
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(), DateUtilChange.DEFAULT_DAY_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();

                    long m = jsonModel_my.getMyraises().get(i).getInterestStartDate();
                    if (m!=0) {
                        time = DateUtilChange.timestamp2String(m, DateUtilChange.DEFAULT_DAY_FORMAT);
                    }else {
                        time = "——";
                    }
//                    DecimalFormat df = new DecimalFormat("0.00");
//                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getRaiserecords().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
//                    String  newrate1=df.format(annualRate);

                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String newrate1 = df.format(annualRate);

                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                   // hashMap.put("state", "募集成功");
                    hashMap.put("state", jsonModel_my.getMyraises().get(i).getGdBenefitReturnStep());
//                    if(compare_date(time)==1){
//                        hashMap.put("state","等待计息");
//                    }
//                    else{
//                        hashMap.put("state", "计息中");
//                    }
                    hashMap.put("starttime", time);
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    datas.add(hashMap);
                }
                if (datas.size() == totalrecords) {
                    mLoading = false;
                } else {
                    totalrecords = datas.size();
                }
                if (mLoading == true) {
                    FM_raise_three.notifyDataSetChanged();
                }
                break;
            case 3:
                for (int i = 0; i < jsonModel_my.getPagerows(); i++) {
//                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMyraises().get(i).getInterestStartDate(),DateUtilChange.DEFAULT_DAY_FORMAT);
//                    int annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate()).multiply(new BigDecimal(100 + "")).intValue();
                    DecimalFormat df = new DecimalFormat("0.00");
                    BigDecimal annualRate = new BigDecimal(jsonModel_my.getMyraises().get(i).getGdAnnualizedBenefitRate().toString()).multiply(new BigDecimal(100 + ""));
                    String  newrate1=df.format(annualRate);

                    switch (jsonModel_my.getMyraises().get(i).getItemStatus()){
                        case "100":
                            m="已退还";
                            break;
                        case "200":
                            m="待退还";
                            break;
                    }
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("name", jsonModel_my.getMyraises().get(i).getItemName().toString());
                    hashMap.put("investMoney", "￥" + new BigDecimal(jsonModel_my.getMyraises().get(i).getRaiseMoney().toString()).setScale(2) + "元");
                    hashMap.put("state", m);
                    hashMap.put("starttime", "-1");
                    hashMap.put("annualRate", newrate1 + "%");
                    hashMap.put("projectTime", jsonModel_my.getMyraises().get(i).getInterestDays() + "天");
                    if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 0) {
                        hashMap.put("repayType", "到期一次性还本付息");
                    } else if (jsonModel_my.getMyraises().get(i).getGdBenefitMode() == 1) {
                        hashMap.put("repayType", "按月付息到期还本");
                    }
                    datas.add(hashMap);
                }
                if (datas.size() == totalrecords) {
                    mLoading = false;
                } else {
                    totalrecords = datas.size();
                }
                if (mLoading == true) {
                    FM_raise_three.notifyDataSetChanged();
                }
                break;
        }
    }

    /**
     *
     * @param time:计息开始时间
     * @return 1:
     */
    public static int compare_date(String time) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date dt2=new Date();
        try {
            Date dt1 = df.parse(time);
            if (dt1.getTime() > dt2.getTime()) {
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }
}
